
const Controller = require('egg').Controller;

/**
 * @controller 项目 project
 */

class ProjectsController extends Controller {
  /**
   * @apikey
   * @summary 获取 项目
   * @description 获取 项目
   * @request query string name project名
   * @request query number state 状态 enum:1,2,3 eg:项目状态.1为正常、2为已归档、3为已在回收站
   * @request query number limit limit
   * @request query number offset offset
   * @router get /api/v1/projects/list
   */
  async findAll() {
    const { ctx, service } = this;

    const { allRule, query } = ctx.helper.tools.findAllParamsDeal({
      rule: ctx.rule.projectPutBodyReq,
      queryOrigin: ctx.query,
      ruleOther: {
        state: {
          ...ctx.rule.projectBodyReq.state,
          required: false,
          type: 'enum',
          values: [1, '1'],
        },
        is_recycle: {
          ...ctx.rule.projectBodyReq.is_recycle,
          type: 'enum',
          values: [0, '0', 1, '1'],
        },
        is_archived: {
          ...ctx.rule.projectBodyReq.is_recycle,
          type: 'enum',
          values: [0, '0', 1, '1'],
        },
        collection: {
          type: 'enum',
          values: [0, '0', 1, '1'],
          required: false,
          description: '是否只显示收藏.1为true,0为false',
        },
      },
    });
    ctx.validate(allRule, query);
    const res = await service.projects.findAll(query);
    ctx.helper.body.SUCCESS({ ctx, res });
  }
}

module.exports = ProjectsController;